<?php
/*
 * Created on 2016-11-1
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 
require_once(dirname(__FILE__)."/../config/include.php");
	
	
function log_save_vr($logs)
{
	$time = date("Ymd H:i:s") ;
	$save_log_filename = dirname(__FILE__)."/log_core_vr.txt" ;
	file_put_contents($save_log_filename,"$time -- $logs .\r\n",FILE_APPEND);
}

	
$GLOBALS['DEBUG_SQL_LOG'] = false ;
$time = date("Ymd H:i:s") ;

$tzid = 0 ;
if(array_key_exists('tzid',$_POST))
{
	$tzid 	= intval(trim($_POST['tzid']));
}
else if(array_key_exists('tzid',$_GET))
{
	$tzid 	= intval(trim($_GET['tzid']));
}

if ($tzid == 0)
{
	$isok = false ;
	if (count($argv) >= 3){
		//print_r($argv);
		$key = addslashes(trim($argv[1])) ;
		if ($key == "tzid"){
			$tzid 	= intval(trim($argv[2])) ;
		}
	}
}
log_save_vr("start create all big image . tzid = $tzid") ;
if ($tzid == 0){
	log_save_vr("error . tzid = $tzid") ;
	echo -1 ;		// 参数错误,没有传递套装id
	exit() ;
}



sql_connect() ;


$et = 1800 ; 
sql_query("update taozhuang_vr_temp set `state` = 1 , `starttime` = unix_timestamp() , `endtime` = unix_timestamp() + $et , `process` = '0%' where  tzid = '$tzid' and  `type` = 1") ;

$tzlist = sql_fetch_rows("select * from taozhuang_vr_buffer where `tzid` = '$tzid' ") ;

if (is_array($tzlist) == false){
	log_save_vr("no find vr data  . tzid = $tzid") ;
	
	echo -2 ;		// 没有数据
	exit() ;
}

$allct = count($tzlist) ;

log_save_vr("allcount = $allct  . tzid = $tzid") ;

$i = 0 ;
foreach($tzlist as $t)
{
	$ac = intval($i * 100 / $allct) ;
	sql_query("update taozhuang_vr_temp set `process` = '$ac %' where  tzid = '$tzid' and  `type` = 1") ;
	
	$id = $t['id'] ;
	$img_list = $t['img_list'] ;	
	$old_img = $t['img_id'] ;
	
	$nm = $tzid."_".$id.".jpg" ;
	$saveinfo = img_set_imglists_toOne($img_list , $nm , $old_img) ;
	sql_query("update taozhuang_vr_buffer set `img_id` = '{$saveinfo[0]}' where `id` = '$id'") ;	

	log_save_vr("process $i / $allct == $ac  . tzid = $tzid , img_id = {$saveinfo[0]}") ;

	$i = $i + 1 ;
}

$ac = 100 ;
sql_query("update taozhuang_vr_temp set `state` = 2 , `process` = '$ac %' where  tzid = '$tzid' and  `type` = 1") ;

log_save_vr("process over . tzid = $tzid") ;

echo 0 ;	// 执行完成返回.
 
?>
